using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using System.Linq.Expressions;
using ACME.Northwind.Service.Interfaces;

namespace ACME.Northwind.Service.IOCExtensions
{
	/// <summary>
	/// This is an extension class for CustomerDemographic DTO objects and lists
	/// </summary>
	public static partial class CustomerDemographicExtension
	{
		#region RunSelect
		/// <summary>
		/// Select all objects from store.
		/// </summary>
		public static void RunSelect(this List<CustomerDemographicDTO> list)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			list.AddRange(proxy.RunSelect());
		}
		#endregion

		#region RunSelect Paged

		/// <summary>
		/// Using the specified Where expression, execute a query against the database to return a paged result set.
		/// </summary>
		public static PagedQueryResults<CustomerDemographicDTO> RunSelect(this List<CustomerDemographicDTO> list, int page, int pageSize, bool ascending, string sortColumn, string linq)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			PagedQueryResults<CustomerDemographicDTO> retval = proxy.RunSelect(page, pageSize, ascending, sortColumn, linq);
			if (retval.GridData != null)
				list.AddRange(retval.GridData);
			return retval;
		}

		#endregion

		#region RunSelect Paged

		/// <summary>
		/// Using the specified Where expression, execute a query against the database to return a result set.
		/// </summary>
		public static void RunSelect(this List<CustomerDemographicDTO> list, string linq)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			list.AddRange(proxy.RunSelect(linq));
		}

		#endregion

		#region Persist

		/// <summary>
		/// Persists this object to store.
		/// </summary>
		public static void Persist(this CustomerDemographicDTO customerdemographic)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			proxy.Persist(customerdemographic);
		}

		/// <summary>
		/// Persists this collection to store.
		/// </summary>
		public static void Persist(this List<CustomerDemographicDTO> customerdemographicList)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			proxy.Persist(customerdemographicList);
		}

		#endregion

		#region CustomerDemographic SelectUsingPK

		/// <summary>
		/// Select a single object from this collection by its primary key.
		/// </summary>
		public static bool SelectByPrimaryKey(this CustomerDemographicDTO customerdemographic, string customertypeid)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			ICustomerDemographicService customerdemographicService = (ICustomerDemographicService)proxy;
			var item = customerdemographicService.SelectByPrimaryKey(customertypeid);
			if (item == null) return false;
			CopyObject(item, customerdemographic);
			return true;
		}

		#endregion

		#region CustomerDemographic Select By Foreign Key
		/// <summary>
		/// Get the related 'CustomerCustomerDemo' DTO list
		/// </summary>
		public static CustomerCustomerDemoDTO[] GetCustomerCustomerDemoList(this CustomerDemographicDTO item)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			ICustomerDemographicService service = (ICustomerDemographicService)proxy;
			return service.GetCustomerCustomerDemoList(item).ToArray();
		}


		#endregion

		#region Delete

		/// <summary>
		/// Delete a single object.
		/// </summary>
		public static void Delete(this CustomerDemographicDTO customerdemographic)
		{
			var proxy = ProxyFactory<CustomerDemographicDTO>.GetProxy();
			ICustomerDemographicService customerdemographicService = (ICustomerDemographicService)proxy;
			customerdemographicService.Delete(customerdemographic);
		}

		#endregion

		/// <summary>
		/// Clones one DTO to another.
		/// </summary>
		internal static void CopyObject(CustomerDemographicDTO source, CustomerDemographicDTO destination)
		{
			destination.CustomerTypeId = source.CustomerTypeId;
			destination.CustomerDesc = source.CustomerDesc;
		}

	}
}
